// pages/resources/index.js
Page({
  data: {
    categoryKey: '',
    categoryTitle: '',
    bookList: []
  },

  onLoad(options) {
    const categoryKey = options.category || 'anxiety'; // 默认一个分类
    const categoryData = this.getCategoryData(categoryKey);

    this.setData({
      categoryKey,
      categoryTitle: categoryData.title,
      bookList: categoryData.books
    });
  },

  goToDetail(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/detail/index?id=${id}`
    });
  },

  getCategoryData(key) {
    const allCategories = {
      anxiety: {
        title: '克服分离焦虑',
        books: [
          { id: 'book1', title: '第一个吻', cover: '/images/coloring.png' },
          { id: 'book2', title: '我不想离开你', cover: '/images/copy_right.png' },
          { id: 'book3', title: '魔法亲亲', cover: '/images/tracing.png' }
        ]
      },
      fathersday: {
        title: '父亲节专题',
        books: [
          { id: 'book4', title: '国王爸爸', cover: '/images/coloring.png' },
          { id: 'book5', title: '我爸爸', cover: '/images/copy_right.png' },
          { id: 'book6', title: '爸爸带我看宇宙', cover: '/images/tracing.png' }
        ]
      }
      // 你可以继续添加更多分类
    };

    return allCategories[key] || { title: '未知分类', books: [] };
  }
});
